package com.Maykk.Demo01;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @ClassName: Demo03
 * @Description: TODO 通过反射实例化 Student 类
 * @Author: MaykkStar@163.com
 */
public class Demo03 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        // 获取 Student 类的 Class 对象
        Class<Student> stuClass = Student.class;
        // 通过 Student 的 Class 对象获取构造方法
        Constructor<Student> con = stuClass.getConstructor(String.class);
        // 通过 newInstance 方法，实例化 Student 对象，参数传递给 newInstance 方法
        Student student = con.newInstance("Maykk");
        // 输出对象
        System.out.println(student);

    }
}
